Quote boolean conditions in shipped Microsoft.TestPlatform.targets - #16404
Merged
Azat Mukhametshin (azat-msft) merged 2 commits intoAug 26, 2026
Conversation
Bare !$(VSTestNoBuild) and $(VsTestUseMSBuildOutput) make MSBuild require the value to parse as a boolean, and it fails the build with MSB4100 when it does not. dotnet test -p:VSTestNoBuild=1 is enough to hit it, and this file ships in Microsoft.TestPlatform.Build, so it fails on the user machine. Compare against 'true' instead. MSBuild's == is boolean aware, so on, yes and TRUE keep routing the same way. Fix microsoft#16396 🤖
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the shipped Microsoft.TestPlatform.targets (from Microsoft.TestPlatform.Build) to avoid MSBuild condition parsing failures when boolean-like properties are set to non-boolean values such as 0/1 or empty, which can break dotnet test on end-user machines.
Changes:
- Quote property references in MSBuild
Conditionexpressions to prevent malformed conditions when properties are unset/empty. - Replace bare boolean negation conditions (e.g.,
!$(...)) with explicit comparisons against'true'to avoid MSB4100 when users pass0/1-style values. - Quote the left-hand side of property default conditions for consistency and robustness when properties are unset.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Azat Mukhametshin (azat-msft)
August 26, 2026 14:39
View session
Azat Mukhametshin (azat-msft)
approved these changes
Aug 26, 2026
Azat Mukhametshin (azat-msft)
enabled auto-merge (squash)
August 26, 2026 15:07
Azat Mukhametshin (azat-msft)
merged commit Aug 26, 2026
3d105b5
into
microsoft:main
20 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dotnet testfails the build when a boolean property holds something that is not a boolean:Bare
!$(X)and$(X)in a condition require the value to parse as a boolean, and1is not one. Three ways in, all reproduced against the shipped file:-p:VSTestNoBuild=1!$(VSTestNoBuild)-p:VSTestNoBuild=!$(VSTestNoBuild)-p:VsTestUseMSBuildOutput=1!$(VsTestUseMSBuildOutput)0/1is a reasonable thing for a user to type, and this file already uses it for_MSBUILDTLENABLEDtwo lines up, so copying the local idiom walks straight into it. The file ships inMicrosoft.TestPlatform.Buildand backsdotnet test, so this fails on the user machine, not on ours.Compare against
'true'instead. MSBuild's==is boolean aware, soon,yesandTRUEstill route the same way. Line 45 now reads'$(VSTestNoBuild)' != 'true', the same as the_VSTestConsolecall site on line 81.The two
VSTestTaskAssemblyFileandVSTestConsolePathdefaults are quoted for consistency with #16325, not because they were broken. MSBuild parses a condition from the raw string, so those already worked when the property was unset or held a path with spaces.Verified by installing the built
Microsoft.TestPlatform.targetsinto the SDK and running the same commands again. All three MSB4100 failures go away and the tests run; the other paths, including terminal logger on and off,VsTestUseMSBuildOutput=falseandMSBUILDENSURESTDOUTFORTASKPROCESSES=1, produce the same output as before.MSBuildLoggerCanBeEnabledByBuildPropertyAndDoesNotEatSpecialChars,MSBuildLoggerCanBeDisabledByBuildPropertyandMSBuildLoggerCanBeDisabledByEnvironmentVariablePropertypass with the new file, and passed before it as the control.CopyTraceDataCollectorArtifactsinMicrosoft.CodeCoverage.targetshas the same problem, but #15794 is rewriting that target, so I left it there.Fix #16396
🤖